mirror of
https://github.com/developersIndia/deviras.git
synced 2025-05-31 14:11:43 +05:30
Compare commits
1 Commits
e5b36db49f
...
community-
Author | SHA1 | Date | |
---|---|---|---|
|
a96b150daf |
@@ -33,7 +33,7 @@
|
|||||||
"test"
|
"test"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"login": "git-bruh",
|
"login": "git-bruh",
|
||||||
"name": "Pratham",
|
"name": "Pratham",
|
||||||
"avatar_url": "https://avatars.githubusercontent.com/u/67585967?v=4",
|
"avatar_url": "https://avatars.githubusercontent.com/u/67585967?v=4",
|
||||||
@@ -59,15 +59,6 @@
|
|||||||
"contributions": [
|
"contributions": [
|
||||||
"code"
|
"code"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"login": "Rancho-rachit",
|
|
||||||
"name": "Rachit Agrawal",
|
|
||||||
"avatar_url": "https://avatars.githubusercontent.com/u/111473259?v=4",
|
|
||||||
"profile": "https://rancho-rachit.github.io/",
|
|
||||||
"contributions": [
|
|
||||||
"code"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"contributorsPerLine": 7,
|
"contributorsPerLine": 7,
|
||||||
|
@@ -79,10 +79,10 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|||||||
<td align="center" valign="top" width="14.28%"><a href="https://animesh-ghosh.github.io/"><img src="https://avatars.githubusercontent.com/u/34956994?v=4?s=100" width="100px;" alt="MaDDogx"/><br /><sub><b>MaDDogx</b></sub></a><br /><a href="https://github.com/developersIndia/deviras/commits?author=Animesh-Ghosh" title="Code">💻</a> <a href="https://github.com/developersIndia/deviras/commits?author=Animesh-Ghosh" title="Tests">⚠️</a></td>
|
<td align="center" valign="top" width="14.28%"><a href="https://animesh-ghosh.github.io/"><img src="https://avatars.githubusercontent.com/u/34956994?v=4?s=100" width="100px;" alt="MaDDogx"/><br /><sub><b>MaDDogx</b></sub></a><br /><a href="https://github.com/developersIndia/deviras/commits?author=Animesh-Ghosh" title="Code">💻</a> <a href="https://github.com/developersIndia/deviras/commits?author=Animesh-Ghosh" title="Tests">⚠️</a></td>
|
||||||
<td align="center" valign="top" width="14.28%"><a href="https://pratham.cc"><img src="https://avatars.githubusercontent.com/u/67585967?v=4?s=100" width="100px;" alt="Pratham"/><br /><sub><b>Pratham</b></sub></a><br /><a href="https://github.com/developersIndia/deviras/commits?author=git-bruh" title="Code">💻</a></td>
|
<td align="center" valign="top" width="14.28%"><a href="https://pratham.cc"><img src="https://avatars.githubusercontent.com/u/67585967?v=4?s=100" width="100px;" alt="Pratham"/><br /><sub><b>Pratham</b></sub></a><br /><a href="https://github.com/developersIndia/deviras/commits?author=git-bruh" title="Code">💻</a></td>
|
||||||
<td align="center" valign="top" width="14.28%"><a href="https://nisarga.me/"><img src="https://avatars.githubusercontent.com/u/45588772?v=4?s=100" width="100px;" alt="Nisarga Adhikary"/><br /><sub><b>Nisarga Adhikary</b></sub></a><br /><a href="https://github.com/developersIndia/deviras/commits?author=ni5arga" title="Code">💻</a></td>
|
<td align="center" valign="top" width="14.28%"><a href="https://nisarga.me/"><img src="https://avatars.githubusercontent.com/u/45588772?v=4?s=100" width="100px;" alt="Nisarga Adhikary"/><br /><sub><b>Nisarga Adhikary</b></sub></a><br /><a href="https://github.com/developersIndia/deviras/commits?author=ni5arga" title="Code">💻</a></td>
|
||||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/lineararray"><img src="https://github.com/lineararray.png?s=100" width="100px;" alt="LinearArray"/><br /><sub><b>LinearArray</b></sub></a><br /><a href="https://github.com/developersIndia/deviras/commits?author=LinearArray" title="Code">💻</a></td>
|
<td align="center" valign="top" width="14.28%"><a href="https://reddit.com/u/LinearArray"><img src="https://i.imgur.com/NTzygIr.jpeg" width="100px;" alt="LinearArray"/><br /><sub><b>LinearArray</b></sub></a><br /><a href="https://github.com/developersIndia/deviras/commits?author=LinearArray" title="Code">💻</a></td>
|
||||||
<td align="center" valign="top" width="14.28%"><a href="https://rancho-rachit.github.io/"><img src="https://avatars.githubusercontent.com/u/111473259?v=4?s=100" width="100px;" alt="Rachit Agrawal"/><br /><sub><b>Rachit Agrawal</b></sub></a><br /><a href="https://github.com/developersIndia/deviras/commits?author=Rancho-rachit" title="Code">💻</a></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<!-- markdownlint-restore -->
|
<!-- markdownlint-restore -->
|
||||||
|
@@ -1,17 +0,0 @@
|
|||||||
# DISCORD BOT TOKEN
|
|
||||||
# MUST HAVE PERMISSIONS TO CREATE EVENTS & MANAGE EVENTS
|
|
||||||
# https://discord.com/developers/applications
|
|
||||||
|
|
||||||
export DISCORD_BOT_TOKEN = "TOKEN"
|
|
||||||
|
|
||||||
# -----------
|
|
||||||
|
|
||||||
# DISCORD SERVER ID (GUILD ID)
|
|
||||||
# developersIndia => 1229786646468362260
|
|
||||||
export DISCORD_GUILD_ID = 1229786646468362260
|
|
||||||
|
|
||||||
# -----------
|
|
||||||
|
|
||||||
# CALANDER ID
|
|
||||||
# developersIndia => "9f1337e4154910eb1bdb3bfac32b88f69546468b1281a6db58f50a909df5049f@group.calendar.google.com"
|
|
||||||
export GOOGLE_CALENDAR_ID = "9f1337e4154910eb1bdb3bfac32b88f69546468b1281a6db58f50a909df5049f@group.calendar.google.com"
|
|
@@ -1,52 +0,0 @@
|
|||||||
# Automation to create events across Google Calendar & Discord
|
|
||||||
|
|
||||||
|
|
||||||
## Description
|
|
||||||
|
|
||||||
This script creates events across [Google Calendar](https://developersindia.in/events-calendar/) & [Discord](https://discord.com/channels/669880381649977354/)
|
|
||||||
|
|
||||||
### First Time Setup
|
|
||||||
|
|
||||||
1. Get Python3
|
|
||||||
|
|
||||||
```bash
|
|
||||||
sudo apt-get install python3 && python3 --version
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Install required packages
|
|
||||||
|
|
||||||
```bash
|
|
||||||
pip install -r requirements.txt
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Add respective tokens in the `.env` file
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cp .sample.env .env
|
|
||||||
```
|
|
||||||
|
|
||||||
1. `DISCORD_BOT_TOKEN`
|
|
||||||
- Get it from [Discord Developers portal](https://discord.com/developers/applications/)) (bot must have MANAGE_EVENT & CREATE_EVENT permission)
|
|
||||||
|
|
||||||
2. `DISCORD_GUILD_ID`
|
|
||||||
- developersIndia's GUID is `1229786646468362260`
|
|
||||||
|
|
||||||
3. `GOOGLE_CALENDAR_ID`
|
|
||||||
- developersIndia calendar is public, `9f1337e4154910eb1bdb3bfac32b88f69546468b1281a6db58f50a909df5049f@group.calendar.google.com`
|
|
||||||
|
|
||||||
4. Connect Google calendar through [Google cloud Console](https://console.cloud.google.com/)
|
|
||||||
1. 4.1 Create a Project on Google Cloud Console
|
|
||||||
2. Search for calendar API and enable it
|
|
||||||
3. Create Credentials -> OAuth Client ID -> Application type as Desktop
|
|
||||||
4. Download the JSON file
|
|
||||||
5. Rename that JSON file as `credentials.json` and save it to the project directory.
|
|
||||||
|
|
||||||
5. `python3 main.py`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### NOTES-
|
|
||||||
|
|
||||||
> - Google authenication is required for the first time.
|
|
||||||
>
|
|
||||||
> - A file `token.json` will be downloaded automatically, and no web login will be needed afterwards.
|
|
@@ -1,57 +0,0 @@
|
|||||||
from datetime import datetime, timedelta
|
|
||||||
import discord
|
|
||||||
from discord.ext import commands
|
|
||||||
|
|
||||||
|
|
||||||
def create_discord_event(
|
|
||||||
bot_token,
|
|
||||||
guild_id,
|
|
||||||
EVENT_NAME,
|
|
||||||
EVENT_DESCRIPTION,
|
|
||||||
EVENT_LOCATION,
|
|
||||||
EVENT_DATE,
|
|
||||||
EVENT_START_TIME,
|
|
||||||
EVENT_END_TIME,
|
|
||||||
):
|
|
||||||
|
|
||||||
bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
|
|
||||||
|
|
||||||
@bot.event
|
|
||||||
async def on_ready():
|
|
||||||
|
|
||||||
# Convert the date string to a datetime object
|
|
||||||
date_object = datetime.strptime(EVENT_DATE, "%Y-%m-%d")
|
|
||||||
|
|
||||||
# Convert the time string to a datetime object
|
|
||||||
start_time_object = datetime.strptime(EVENT_START_TIME, "%H:%M")
|
|
||||||
end_time_object = datetime.strptime(EVENT_END_TIME, "%H:%M")
|
|
||||||
|
|
||||||
# Combine the date and time objects
|
|
||||||
st = date_object.replace(
|
|
||||||
hour=start_time_object.hour, minute=start_time_object.minute
|
|
||||||
).astimezone()
|
|
||||||
et = date_object.replace(
|
|
||||||
hour=end_time_object.hour, minute=end_time_object.minute
|
|
||||||
).astimezone()
|
|
||||||
|
|
||||||
gg = bot.get_guild(guild_id)
|
|
||||||
|
|
||||||
try:
|
|
||||||
event = await gg.create_scheduled_event(
|
|
||||||
name=EVENT_NAME,
|
|
||||||
entity_type=discord.EntityType.external,
|
|
||||||
description=EVENT_DESCRIPTION,
|
|
||||||
start_time=st,
|
|
||||||
end_time=et,
|
|
||||||
location=EVENT_LOCATION,
|
|
||||||
privacy_level=discord.PrivacyLevel.guild_only,
|
|
||||||
)
|
|
||||||
print("Discord Event: ", event.url)
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
|
|
||||||
await bot.close()
|
|
||||||
|
|
||||||
# Run the bot
|
|
||||||
bot.run(bot_token)
|
|
@@ -1,58 +0,0 @@
|
|||||||
import os.path
|
|
||||||
|
|
||||||
from google.auth.transport.requests import Request
|
|
||||||
from google.oauth2.credentials import Credentials
|
|
||||||
from google_auth_oauthlib.flow import InstalledAppFlow
|
|
||||||
from googleapiclient.discovery import build
|
|
||||||
|
|
||||||
SCOPES = ["https://www.googleapis.com/auth/calendar"]
|
|
||||||
|
|
||||||
|
|
||||||
def create_google_calendar_event(
|
|
||||||
calendar_id, name, description, location, date, start_time, end_time
|
|
||||||
):
|
|
||||||
|
|
||||||
creds = None
|
|
||||||
|
|
||||||
# The file token.json stores the user's access and refresh tokens
|
|
||||||
if os.path.exists("token.json"):
|
|
||||||
creds = Credentials.from_authorized_user_file("token.json", SCOPES)
|
|
||||||
|
|
||||||
# If there are no (valid) credentials available, let the user log in.
|
|
||||||
if not creds or not creds.valid:
|
|
||||||
if creds and creds.expired and creds.refresh_token:
|
|
||||||
creds.refresh(Request())
|
|
||||||
else:
|
|
||||||
print("Login to your Google account. [THIS IS A ONE TIME PROCESS]")
|
|
||||||
flow = InstalledAppFlow.from_client_secrets_file("credentials.json", SCOPES)
|
|
||||||
creds = flow.run_local_server(port=0)
|
|
||||||
# Save the credentials for the next run
|
|
||||||
with open("token.json", "w") as token:
|
|
||||||
token.write(creds.to_json())
|
|
||||||
|
|
||||||
try:
|
|
||||||
service = build("calendar", "v3", credentials=creds)
|
|
||||||
start = f"{date}T{start_time}:00"
|
|
||||||
end = f"{date}T{end_time}:00"
|
|
||||||
event = {
|
|
||||||
"summary": name,
|
|
||||||
"location": location,
|
|
||||||
"description": description,
|
|
||||||
"start": {
|
|
||||||
"dateTime": start,
|
|
||||||
"timeZone": "Asia/Kolkata",
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"dateTime": end,
|
|
||||||
"timeZone": "Asia/Kolkata",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
event = service.events().insert(calendarId=calendar_id, body=event).execute()
|
|
||||||
|
|
||||||
print("Google calendar: %s" % (event.get("htmlLink")))
|
|
||||||
return event
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
return None
|
|
@@ -1,29 +0,0 @@
|
|||||||
import os
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
|
|
||||||
load_dotenv()
|
|
||||||
bot_token = os.getenv('DISCORD_BOT_TOKEN')
|
|
||||||
guild_id = int(os.getenv('DISCORD_GUILD_ID'))
|
|
||||||
calendar_id = os.getenv('GOOGLE_CALENDAR_ID')
|
|
||||||
|
|
||||||
def get_input():
|
|
||||||
NAME = input("Event title: ")
|
|
||||||
DESCRIPTION = input("Event description: ")
|
|
||||||
LOCATION = input("Event location (red -> for developersindia subreddit): ")
|
|
||||||
if LOCATION == "red":
|
|
||||||
LOCATION = "https://www.reddit.com/r/developersindia/"
|
|
||||||
DATE = input("Enter the event date (yyyy-mm-dd): ")
|
|
||||||
START_TIME = input("Enter the event start time (hh:mm)- ")
|
|
||||||
END_TIME = input("Enter the event end time (hh:mm)- ")
|
|
||||||
|
|
||||||
return NAME, DESCRIPTION, LOCATION, DATE, START_TIME, END_TIME
|
|
||||||
|
|
||||||
EVENT_NAME, EVENT_DESCRIPTION, EVENT_LOCATION, EVENT_DATE, EVENT_START_TIME, EVENT_END_TIME = get_input()
|
|
||||||
|
|
||||||
# Execute create_discord_event
|
|
||||||
from discord_bot import create_discord_event
|
|
||||||
create_discord_event(bot_token, guild_id, EVENT_NAME, EVENT_DESCRIPTION, EVENT_LOCATION, EVENT_DATE, EVENT_START_TIME, EVENT_END_TIME)
|
|
||||||
|
|
||||||
# Execute google_calendar_event
|
|
||||||
from google_calendar import create_google_calendar_event
|
|
||||||
create_google_calendar_event(calendar_id, EVENT_NAME, EVENT_DESCRIPTION, EVENT_LOCATION, EVENT_DATE, EVENT_START_TIME, EVENT_END_TIME)
|
|
@@ -1,5 +0,0 @@
|
|||||||
discord.py
|
|
||||||
google-api-python-client
|
|
||||||
google-auth-httplib2
|
|
||||||
google-auth-oauthlib
|
|
||||||
python-dotenv
|
|
Reference in New Issue
Block a user