added logo
This commit is contained in:
parent
de1f1e9d55
commit
dddcf9d75b
@ -1,4 +1,7 @@
|
||||
# Dask bot*
|
||||
![Daskbot logo] (logo.png)
|
||||
|
||||
# Dask bot
|
||||
|
||||
Dask bot(or however you want to name it) is an open source discord bot which allows you to visualize the weather, your events saved in a google calendar and also mark your tasks in google tasks as completed for the day. It also keeps log of the tasks completed so at the end of your day, you can check out who did what at what time.
|
||||
This bot is meant to be launched and maintained by yourself for full control on what you want the bot to be. So no third party can come between your bot and your group (Except the weather and google services ofcourse).
|
||||
|
||||
|
||||
@ -1,61 +0,0 @@
|
||||
import sqlite3
|
||||
|
||||
class UserLocation:
|
||||
def __init__(self, db_name='users_location.db'):
|
||||
self.db_name = db_name
|
||||
self.create_table()
|
||||
|
||||
def create_table(self):
|
||||
conn = sqlite3.connect(self.db_name)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS user_locations (
|
||||
username TEXT NOT NULL,
|
||||
user_id INTEGER PRIMARY KEY,
|
||||
location TEXT NOT NULL
|
||||
)
|
||||
''')
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def set_user_location(self, username:str, user_id: int, location: str):
|
||||
conn = sqlite3.connect(self.db_name)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
INSERT INTO user_locations (username, user_id, location) VALUES (?, ?, ?) ON CONFLICT(user_id) DO UPDATE SET location=excluded.location''', (username, user_id, location))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def get_user_location(self, user_id: int) -> str:
|
||||
conn = sqlite3.connect(self.db_name)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('SELECT location FROM user_locations WHERE user_id = ?', (user_id,))
|
||||
row = cursor.fetchone()
|
||||
conn.close()
|
||||
return row[0] if row else None
|
||||
|
||||
class TaskCompleted:
|
||||
def __init__(self, db_name='tasks_completed.db'):
|
||||
self.db_name = db_name
|
||||
self.create_table()
|
||||
|
||||
def create_table(self):
|
||||
conn = sqlite3.connect(self.db_name)
|
||||
cursor = conn.execute('''
|
||||
CREATE TABLE IF NOT EXISTS task_completed (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL,
|
||||
username TEXT NOT NULL,
|
||||
task TEXT NOT NULL,
|
||||
time TEXT NOT NULL
|
||||
)''')
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def set_info(self, user_id:int, username: str, task: str, time: str):
|
||||
conn = sqlite3.connect(self.db_name)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
INSERT INTO task_completed (user_id, username, task, time) VALUES (?, ?, ?, ?)''', (user_id, username, task, time))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
39
bot/task.py
39
bot/task.py
@ -1,39 +0,0 @@
|
||||
import asyncio, json, datetime, discord
|
||||
from discord.ui import View, Select
|
||||
|
||||
class TaskSelect(Select):
|
||||
def __init__(self, options):
|
||||
super().__init__(placeholder="Choose a task to complete...",
|
||||
min_values=1, max_values=1, options=options)
|
||||
|
||||
async def callback(self, interaction: discord.Interaction):
|
||||
payload = json.loads(self.values[0])
|
||||
tasklist_id = payload["tasklist_id"]
|
||||
task_id = payload["task_id"]
|
||||
|
||||
await interaction.response.defer(thinking=True)
|
||||
try:
|
||||
service = build_tasks_service()
|
||||
task = await asyncio.to_thread(lambda:
|
||||
service.tasks().get(tasklist=tasklist_id, task=task_id).execute())
|
||||
if not task:
|
||||
await interaction.followup.send("Task not found.", ephemeral=True)
|
||||
return
|
||||
|
||||
now = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat()
|
||||
body = dict(task)
|
||||
body["status"] = "completed"
|
||||
body["completed"] = now
|
||||
|
||||
updated = await asyncio.to_thread(lambda: service.tasks().update(tasklist=tasklist_id, task=task_id, body=body).execute())
|
||||
|
||||
if updated.get("status") == "completed":
|
||||
await interaction.followup.send("Failed to mark completed.", ephemeral=True)
|
||||
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"Error: {e}", ephemeral=True)
|
||||
|
||||
class TasksView(View):
|
||||
def __init__(self, options, timeout=120):
|
||||
super().__init__(timeout=timeout)
|
||||
self.add_item(TaskSelect(options))
|
||||
@ -1,34 +0,0 @@
|
||||
import requests
|
||||
import os
|
||||
from geopy.geocoders import Nominatim
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
WEATHER_TOKEN = os.getenv("WEATHER_TOKEN")
|
||||
|
||||
class OpenWeatherMapAPIClient:
|
||||
def __init__(self, api_token, name):
|
||||
self.base_url = "https://api.openweathermap.org"
|
||||
self._api_token = WEATHER_TOKEN
|
||||
self.name = name
|
||||
|
||||
def get_geodata(self, location):
|
||||
geolocator = Nominatim(user_agent=self.name)
|
||||
geodata = geolocator.geocode(location, language="en-us").raw
|
||||
|
||||
return geodata["lat"], geodata["lon"]
|
||||
|
||||
def get_current_weather(self, location, units="metric"):
|
||||
url = f"{self.base_url}/data/2.5/weather"
|
||||
lat, lon = self.get_geodata(location)
|
||||
params = {
|
||||
"lat": lat,
|
||||
"lon": lon,
|
||||
"units": units,
|
||||
"appid": self._api_token,
|
||||
}
|
||||
|
||||
response = requests.get(url, params=params)
|
||||
data = response.json()
|
||||
|
||||
return data
|
||||
Loading…
x
Reference in New Issue
Block a user